// PaperSelection.java (结合Visitor模式)
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class PaperSelection {
    private final Map<Paper, Student> selections = new HashMap<>();

    public boolean addSelection(Student student, Paper paper) {
        if (!selections.containsKey(paper)) {
            selections.put(paper, student);
            return true;
        }
        return false;
    }

    public boolean isSelected(Paper paper) {
        return selections.containsKey(paper);
    }

    public Map<Paper, Student> getSelections() {
        return new HashMap<>(selections); // 防御性复制
    }

    // Visitor模式支持
    public void accept(PaperSelectionVisitor visitor) {
        visitor.visit(this);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<Paper, Student> entry : selections.entrySet()) {
            sb.append(entry.getKey()).append(" selected by ").append(entry.getValue().getName()).append("\n");
        }
        return sb.toString();
    }
}